﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KnowledgeSource
{
    public class Utils
    {
        public List<string> MakeListStringFromSentence(string sentence)
        {
            return new List<string>(sentence.Split(' '));
        }

        public string MakeSentenceFromListString(List<string> sentence)
        {
            string result = "";

            foreach (var word in sentence)
            {
                result += word + ' ';
            }
            result = result.Substring(0, result.Length - 1);
            return result;
        }

        public List<string> RemoveRedundantDescription(List<string> input)
        {
            var result = new List<string>();
            foreach (var v in input)
            {
                try
                {
                    var temp = v.Substring(0, v.IndexOf("(") - 1);
                    result.Add(temp);
                }
                catch (Exception ex)
                {
                    result.Add(v);
                }
            }
            return result;
        }


        private int PossibilitiesCount(List<List<string>> possibleResults)
        {
            int result = 0;

            if (possibleResults.Count == 0)
            {
                return 0;
            }
            else
            {
                result = 1;
                foreach (var variants in possibleResults)
                {
                    result *= variants.Count;
                }
            }

            return result;
        }

        public List<string> CreateSentenceFromAllPosibilities(List<List<string>> possibleResults)
        {
            var posibilitiesCount = PossibilitiesCount(possibleResults);
            var createdAllSentenceCombination = new List<List<string>>();
            var results = new List<string>();
            var pointer = 0;
            for (int i = 0; i < posibilitiesCount; i++)
            {
                createdAllSentenceCombination.Add(new List<string>());
            }
            foreach (var variant in possibleResults)
            {
                for (int i = 0; i < posibilitiesCount; i++)
                {
                    createdAllSentenceCombination[i].Add(variant[pointer]);
                    pointer++;
                    if (pointer == variant.Count)
                    {
                        pointer = 0;
                    }
                }
            }
            foreach (var list in createdAllSentenceCombination)
            {
                results.Add(MakeSentenceFromListString(list));
            }
            return results;
        }

    }
}
